{ INFORMATICS.MCCME.RU
  Problem statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=1483
  Verdict: Accepted
}
type time=record
                h:0..23;
                m,s:0..59;
      end;
var t1,t2,t3:time;
function is_earlier(t1,t2:time):boolean;
begin
if t1.h>t2.h then result:=true else
if t1.h<t2.h then result:=false else begin
   if t1.m>t2.m then result:=true else
   if t1.m<t2.m then result:=false else begin
      if t1.s>t2.s then result:=true else result:=false;
   end;
end;
result:=not result;
end;
procedure interval(var d:time; t1,t2:time);
var t:time;
begin
if is_earlier(t2,t1) then begin
   t:=t1;
   t1:=t2;
   t2:=t;
end;
d.h:=t2.h-t1.h;
if t2.m<t1.m then begin
   d.m:=t2.m+60-t1.m;
   dec(d.h);
end else d.m:=t2.m-t1.m;
if t2.s<t1.s then begin
   d.s:=t2.s+60-t1.s;
   dec(d.m);
end else d.s:=t2.s-t1.s;
end;
begin
Assign(input,'input.txt');
Assign(output,'output.txt');
reset(input);
rewrite(output);
read(t1.h,t1.m,t1.s);
read(t2.h,t2.m,t2.s);
interval(t3,t1,t2);
writeln(t3.h*3600+t3.m*60+t3.s);
end.
 